package com.student.xujiang.myallstudent.retrofit2.retrofit2_2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.student.xujiang.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class Retrifit2_2Activity extends AppCompatActivity implements Callback<Tngon> {

    String TAG = this.getClass().getSimpleName();
    @BindView(R.id.Retrifit2_2_tv)
    TextView Retrifit22Tv;
    @BindView(R.id.activity_retrifit2_2)
    RelativeLayout activityRetrifit22;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrifit2_2);
        ButterKnife.bind(this);

        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl("http://www.tngou.net")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Service2 service2 = retrofit.create(Service2.class);
        Call<Tngon> list = service2.getList("cook", 0, 1, 20);
        list.enqueue(this);

    }

    @Override
    public void onResponse(Call<Tngon> call, Response<Tngon> response) {
        List<Cook> list = response.body().getList();

        Log.i(TAG, list.toString());

        Retrifit22Tv.setText(list.toString());


//        for(Cook cook:list){
//            Log.i(TAG,cook.toString());
//        }


    }

    @Override
    public void onFailure(Call<Tngon> call, Throwable t) {
        t.printStackTrace();
    }
}
